public partial class AudioMsgForm : Form { private int fileIndex; private AudioFileMaker audioFileMaker = new AudioFileMaker(); private IAudioPlayer audioPlayer; private IMicrophoneCapturer microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0); private Byte[] audioData = new byte[0]; public string StorePath { get { return String.Format("语音备忘\\AudioMsg{0}.ad", this.fileIndex); } } public AudioMsgForm() { InitializeComponent(); this.microphoneCapturer.AudioCaptured = new ESBasic.CbGeneric<byte[]>(microphoneCapturer_AudioCaptured); this.audioPlayer = PlayerFactory.CreateAudioPlayer(0, this.microphoneCapturer.SampleRate, this.microphoneCapturer.ChannelCount); if(!Directory.Exists("语音备忘")) { Directory.CreateDirectory("语音备忘"); } string[] fileName = Directory.GetFiles("语音备忘"); foreach (string name in fileName) { this.fileIndex ; } } void microphoneCapturer_AudioCaptured(byte[] data) { this.audioData = BufferJointer.Joint(this.audioData, data); this.decibelDisplayer1.DisplayAudioData(data); } private void button_start_Click(object sender, EventArgs e) { this.microphoneCapturer.Start(); this.label_notify.Text = "正在录音!"; this.label_notify.ForeColor = Color.Red; this.button_start.Enabled = false; this.button_stop.Enabled = true; } private void button_stop_Click(object sender, EventArgs e) { this.microphoneCapturer.Stop(); File.WriteAllBytes(this.StorePath, this.audioData); this.label_notify.Text = "录音完成!"; this.label_notify.ForeColor = Color.Blue; this.LoadAduioFileList(); this.button_start.Enabled = true; this.button_stop.Enabled = false; this.fileIndex ; return; } private void toolStripButton1_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.toolStripComboBox1.SelectedText)) { MessageBox.Show("请选择列表中的一项!"); this.toolStripComboBox1.DroppedDown = true; return; } this.audioPlayer.Play(File.ReadAllBytes("语音备忘\\" this.toolStripComboBox1.SelectedText)); } private void AudioMsgForm_Shown(object sender, EventArgs e) { this.LoadAduioFileList(); this.button_stop.Enabled = false; } private void LoadAduioFileList() { this.toolStripComboBox1.Items.Clear(); string[] fileName = Directory.GetFiles("语音备忘"); foreach (string name in fileName) { string shortName = name.Substring(name.LastIndexOf("\\") 1, name.Length - 1 - name.LastIndexOf("\\")); this.toolStripComboBox1.Items.Add(shortName); } } private void toolStripButton2_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.toolStripComboBox1.SelectedText)) { MessageBox.Show("请选择列表中的一项!"); this.toolStripComboBox1.DroppedDown = true; return; } if (!Directory.Exists("mp3目录")) { Directory.CreateDirectory("mp3目录"); } string path= String.Format("mp3目录\\{0}.mp3", Path.GetFileNameWithoutExtension(this.toolStripComboBox1.SelectedText)); this.audioFileMaker.Initialize(path, this.microphoneCapturer.SampleRate, this.microphoneCapturer.ChannelCount); this.audioFileMaker.AddAudioFrame(File.ReadAllBytes("语音备忘\\" this.toolStripComboBox1.SelectedText)); this.audioFileMaker.Close(true); DialogResult dialogResult = MessageBox.Show("转存成功,是否打开目录查看?", "提醒", MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Process.Start("explorer.exe", "mp3目录"); } } }
下载C# 录制语音 保存成mp3格式 并播放用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论